package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.vo.PageResult;
import com.flyduck.common.vo.Result;
import com.flyduck.system.service.SysRoleService;
import com.flyduck.system.vo.role.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: flyduck-platform2
 * @description: 系统:角色接口
 * @author: flyduck
 * @create: 2021-03-05 17:43
 **/
@Api(tags = "系统:角色接口")
@RestController
@RequestMapping("/system/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation("获取角色分页")
    @PostMapping("/page")
    public Result getRolePageList(@RequestBody SysRoleReqVO reqVo,
                                   @RequestParam(value = "page",required = true) Integer page,
                                   @RequestParam(value = "size",required = true) Integer size){
        PageResult<SysRoleRespVO> rolePage = sysRoleService.getRolePageList(reqVo, page, size);
        return Result.success(rolePage);
    }


    @IgnoreAuth
    @ApiOperation("获取角色详情")
    @GetMapping("/detail")
    public Result getRoleDetail(@RequestParam(value = "id",required = true) Long id){
        SysRoleDetailRespVO respVO = sysRoleService.getRoleDetail(id);
        return Result.success(respVO);
    }

    @ApiOperation("新增角色")
    @PostMapping("/add")
        public Result addRole(@RequestBody @Validated SysRoleAddReqVO reqVo){
        boolean flag = sysRoleService.addRole(reqVo);
        return Result.success(flag,"新增成功");
    }

    @ApiOperation("编辑角色")
    @PutMapping("/update")
    public Result updateRole(@RequestBody @Validated SysRoleUpdateReqVO reqVo){
        boolean flag = sysRoleService.updateRole(reqVo);
        return Result.success(flag,"编辑成功");
    }

    @ApiOperation("删除角色")
    @DeleteMapping("/delete")
    public Result deleteRole(@RequestParam(value = "id",required = true) Long id){
        boolean flag = sysRoleService.deleteRole(id);
        return Result.success(flag,"删除成功");
    }

    @IgnoreAuth
    @ApiOperation("获取角色下拉")
    @GetMapping("/select")
    public Result getRoleSelect(){
        List<SysRoleSelectRespVO> roleList = sysRoleService.getRoleSelect();
        return Result.success(roleList);
    }
}
